package com.css.masterslave.bean;

import com.css.masterslave.enums.DBTypeEnum;

import java.util.concurrent.atomic.AtomicInteger;

public class DBContextHolder
{
    private static final ThreadLocal<DBTypeEnum> contextHolder = new ThreadLocal<>();
    private static final AtomicInteger counter=new AtomicInteger(-1);
    public static void set(DBTypeEnum dbTypeEnum){
        contextHolder.set(dbTypeEnum);
    }
    public static DBTypeEnum get(){
       return   contextHolder.get();
    }
    public static void master(){
        set(DBTypeEnum.MASTER);
        System.out.println("切换到主数据库");
    }
    public static void slave(){
        set(DBTypeEnum.SLAVE1);
        System.out.println("切换到从数据库");
    }
}
